﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/m.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
    <link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
    <link href="../assets/img/validate/validate.css" rel="stylesheet">
    <link href="../assets/css/plugins/iCheck/custom.css" rel="stylesheet" />
    <link href="../assets/css/shelf/addshop.css" rel="stylesheet" />
    <style type="text/css">
        .module-info .control-label {
            float: left;
            text-align: right;
            min-width: 110px;
        }

        @media (min-width:768px) {
            .modal-dialog {
                width: 768px;
                margin: 10px auto;
            }
        }

        @media (min-width: 1024px) {
            .modal-dialog {
                width: 1024px;
                margin: 10px auto;
            }
        }

        .modal-dialog {
            float: none;
            display: block;
            margin: auto;
        }
        /*图片样式*/
        img.face {
            max-width: 200px;
            max-height: 200px;
        }

        button.fa:before {
            margin-right: 5px;
        }

        dl {
        }

            dl dt {
                float: left;
                text-align: right;
                padding: 0 15px;
            }

            dl dd {
                float: left;
                width: calc(100%-50px);
            }

        nav ul.pagination {
            margin: 0;
        }

        #pro-list-choosen div.thumbnail > img,
        #pro-list-to-choose div.thumbnail > img {
            height: 58px;
        }

        div.thumbnail > .caption > h4 {
            white-space: nowrap;
            overflow: hidden;
        }

        .mix-images div.thumbnail > img {
            height: 250px;
        }

        ul.product-color-list {
            margin: 0;
            padding: 0;
        }

            ul.product-color-list li {
                float: left;
                width: 250px;
                margin: 5px;
                border: 1px solid #efefef;
                list-style: none;
            }

                ul.product-color-list li.selected {
                    border: 1px solid #ff1493;
                }
                label {
                       margin: 12px 0px 10px 1px;
                }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <div class="btns-container"></div>
            <div class="condition">
                <label>店铺信息：</label>
                <input class="form-control input-w160" id="search-CodeOrName" placeholder="输入店铺编码或名称……" />
                <label>合同期：</label>
                <input type="text" class="form-control layer-date" readonly="readonly" id="search-start" placeholder="合同开始时间" />
                <label class="to">到</label>
                <input type="text" class="form-control layer-date" readonly="readonly" id="search-end" placeholder="合同结束时间" />
            </div>
            <div class="right-content-box">
                <div class="ibox-content">
                    <table class="footable table table-stripped">
                        <thead></thead>
                        <tbody id="pageList"></tbody>
                    </table>
                </div>
            </div>

            <div class="pageControl"></div>
        </div>
    </div>

    <div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
        <form id="checkModuleForm" method="get" action="#">
            <div class="modal-dialog">
                <div class="modal-content animated bounceInRight">
                    <div class="modal-header">
                        <span class="editTitle">客户信息</span>
                        <button type="button" class="close" data-dismiss="modal">
                            <span aria-hidden="true">&times;</span>
                            <span class="sr-only">关闭</span>
                        </button>
                    </div>
                    <div id="message" style="display: none"></div>
                    <div class="container">
                        <div class="row ">
                            <div class="col-xs-8 col-sm-8 col-md-8 col-lg-7">
                                <div class="row">
                                    <div class="ShowClientCode" style="line-height: 25px; border-bottom: 1px solid #ccc; padding-left: 10px; padding-top: 5px;padding-bottom:-5px;">客户代码</div>
                                </div>
                                <div class="row ">
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">店铺名称：</label>
                                        </div>
                                        <div class="col-xs-8">
                                            <input id="ShopName" name="ShopName" placeholder=""
                                                datacol="yes" err="店铺名称" checkexpession="NotNull"
                                                maxlength="100" class="form-control input-w220 required" />
                                        </div>
                                    </div>

                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">店铺编码：</label>
                                        </div>
                                        <div class="col-xs-8">
                                            <input id="ShopCode" name="ShopCode" placeholder=""
                                                datacol="yes" err="店铺编码" checkexpession="NotNull"
                                                maxlength="20" class="form-control input-w220 required" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row clearfix">
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">店铺店长：</label>
                                        </div>
                                        <div class="col-xs-8">
                                            <input id="ShopLinkMan" name="ShopLinkMan" placeholder=""
                                                datacol="yes" err="店铺店长" checkexpession=""
                                                maxlength="20" class="form-control input-w220 required" />
                                        </div>
                                    </div>
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">店铺电话：</label>
                                        </div>
                                        <div class="col-xs-8">
                                            <input id="ShopTelePhone" name="ShopTelePhone" placeholder=""
                                                datacol="yes" err="店铺电话" checkexpession=""
                                                maxlength="20" class="form-control input-w220 required" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row ">
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">注册名称：</label>
                                        </div>
                                        <div class="col-xs-8">
                                            <input id="RegistName" name="RegistName" placeholder=""
                                                datacol="yes" err="注册名称" checkexpession="NotNull"
                                                maxlength="100" class="form-control input-w220 required" />
                                        </div>
                                    </div>
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">营业执照：</label>
                                        </div>
                                        <div class="col-xs-8">
                                            <input id="RegistCode" name="RegistCode" placeholder=""
                                                datacol="yes" err="营业执照号" checkexpession="NotNull"
                                                maxlength="18" class="form-control input-w220 required" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row ">
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">注册地址：</label>
                                        </div>
                                        <div class="col-xs-8">
                                            <input id="RedistAddress" name="RedistAddress" placeholder=""
                                                datacol="yes" err="店铺注册地址" checkexpession="NotNull"
                                                maxlength="100" class="form-control input-w220 required" />
                                        </div>
                                    </div>
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">开户行：</label>
                                        </div>
                                        <div class="col-xs-8">
                                            <input id="BankName" name="BankName" placeholder=""
                                                datacol="yes" err="开户行" checkexpession="NotNull"
                                                maxlength="50" class="form-control input-w220 required" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row ">
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">账号：</label>
                                        </div>
                                        <div class="col-xs-8">
                                            <input id="AccountCode" name="AccountCode" placeholder=""
                                                datacol="yes" err="账号" checkexpession="NotNull"
                                                maxlength="20" class="form-control input-w220 required" />
                                        </div>
                                    </div>
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">合同扣点：</label></div>
                                        <div class="col-xs-8">
                                            <input id="Discount" name="Discount" placeholder=""
                                                datacol="yes" err="合同扣点" checkexpession="Decimal"
                                                maxlength="20" class="form-control input-w220 required" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row clearfix">
                                       <div class="col-xs-6">
                                    <div class="col-xs-4">
                                        <label class="control-label">合同期：</label>
                                    </div>
                                    <div class="col-xs-8">
                                        <input id="ContractBeginDate" name="ContractBeginDate" placeholder=""
                                            datacol="yes" err="合同期开始" checkexpession="NotNull"
                                            maxlength="20" class="form-control input-w220 required" />
                                    </div>
                                           </div>
                                       <div class="col-xs-6">
                                    <div class="col-xs-4">
                                         <label class="control-label">至:</label></div>
                                        <div class="col-xs-8"><input id="ContractEndDate" name="ContractEndDate" placeholder=""
                                            datacol="yes" err="合同期结束" checkexpession="NotNull"
                                            maxlength="20" class="form-control input-w220 required" />
                                    </div>
                                           </div>
                                </div>
                                   <div class="row ">
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">合同号：</label>
                                        </div>
                                        <div class="col-xs-8">
                                            <input id="ContractCode" name="ContractCode" placeholder=""
                                                datacol="yes" err="合同号" 
                                                maxlength="30" class="form-control input-w220" />
                                        </div>
                                    </div>
                                    <div class="col-xs-6">
                                        <div class="col-xs-4">
                                            <label class="control-label">合同状态：</label></div>
                                        <div class="col-xs-8">
                                            <input id="ContractState" name="ContractState" placeholder=""
                                                datacol="yes" err="合同状态"
                                                maxlength="20" class="form-control input-w220" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col col-xs-4 col-sm-4 col-md-4 col-lg-3">
                                <div class="row">
                                    <div class="" style="line-height: 25px; border-bottom: 1px solid #ccc; padding-left: 10px; padding-top: 5px;">营业执照附件</div>
                                </div>
                                <div class="row ">
                                        <div class="panel panel-primary">
                                            <div class="panel-body">
                                                <div class="row">
                                                    <div class="progress">
                                                        <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em; width: 0%;">0%</div>
                                                    </div>
                                                    <div class="mix-images"></div>
                                                    <div class="col col-xs-12 upload-panel">
                                                        <div class="thumbnail">
                                                            <div id="div-addImage" style="width: 100%; text-align: center; border: 1px solid #cacaca; padding: 58px 0;"><i class="fa fa-plus fa-5x"></i></div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="panel-footer hidden">
                                                <div style="display: none">
                                                    <input type="file" multiple="multiple" accept="image/jpeg" />
                                                </div>
                                                <p>
                                                    <button type="button" class="btn btn-warning fa fa-upload">上传</button></p>
                                            </div>
                                        </div>
                                    </div>
                            </div>
                        </div>
                    </div>

                    <input id="ShopId" type="hidden" value="" /><input id="BigAreaName" type="hidden" value="" />
                    <%--图片显示--%>
                    <div class="modal-footer">
                        <button type="button" id="addModuleBtn" class="btn btn-primary">保存</button>
                        <button type="button" id="closeAddBox" class="btn btn-white" data-dismiss="modal">关闭</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/plugins/fancybox/jquery.fancybox.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/img/validate/learunui-validator.js"></script>
    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/page/addressConfig.js"></script>
    <script src="../assets/js/common.js"></script>
    <script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>
    <%--图片处理--%>
    <script src="../assets/js/bootbox.min.js"></script>
    <div style="display: none">
        <div id="dialog-product-choose-color">
            <ul class="product-color-list "></ul>
        </div>
    </div>
    <script id="p1" type="text/html">
        <div class="col col-xs-12">
            <div class="thumbnail">
                <img src="../assets/img/s.gif" style="background-image: url({{d.Url}}); background-size: contain; background-repeat: no-repeat; background-position: center;" />
                <div class="caption">
                    <p>
                        <button type="button" class="btn btn-danger fa fa-remove" data-id="{{d.ID}}">移除</button>
                    </p>
                </div>
            </div>
        </div>
    </script>
    <script type="application/javascript">
        $(document).ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //当前页数
            var page = 1;
            commonUtil.loadBtnList(ModuleID, function () {
                $('#editBtn').attr("disabled", "disabled");
                $('#deleteBtn').attr('disabled', 'disabled');
                rScroll();
            });

            //用于判断是否调用删除api
            var realDelete = false;

            //初始化单选框、复选框样式
            $(".i-checks").iCheck({
                checkboxClass: "icheckbox_square-green",
                radioClass: "iradio_square-green"
            });

            //初始化各参数
            var _ClientID = null;
            var _ClientCode = null;
            var _ShopCode = null;
            var _ShopID = null;
            var _ShopName = null;
            var _RegistName = null;
            var _RegistCode = null;
            var _RedistAddress = null;
            var _BankName = null;
            var _AccountCode = null;
            var _ShopLinkMan = null;
            var _ShopTelePhone = null;
            var _ContractBeginDate = null;
            var _ContractEndDate = null;
            var _Discount = null;

            //图片处理
            $('.progress').hide();

            function deleteImage(id) {
                A.API('Image', 'Remove', {
                    id: id
                }, function (data) {
                    $('.upload-panel').fadeIn();
                });
            }

            function addImage(file) {
                //$(this).parents('div.col:first').remove();
                file.Url = Y.GetPath(file.Url);
                var tpl = laytpl(document.getElementById('p1').innerHTML);
                $(tpl).empty();
                var result = tpl.render(file);
                var el = $(result);
                var btnRemove = el.find('button.fa-remove');
                btnRemove.click(function () {
                    swal({
                        title: "您确定要删除这张图片吗",
                        text: "删除后将无法恢复，请谨慎操作！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "删除",
                        closeOnConfirm: false
                    }, function () {
                        deleteImage($(btnRemove).data('id'));
                        $(btnRemove).parents('div.col:first').remove();
                        //$('.upload-panel').fadeIn();
                        swal("删除成功！", "您已经永久删除了这条信息。", "success");
                    });
                });
                $('.mix-images').append(el);
            }

            function addOldImage(file) {
                file.Url = Y.GetPath(file.Url);
                var tpl = laytpl(document.getElementById('p1').innerHTML);
                var result = tpl.render(file);
                var el = $(result);
                var btnRemove = el.find('button.fa-remove');
                btnRemove.click(function () {
                    swal({
                        title: "您确定要删除这张图片吗",
                        text: "删除后将无法恢复，请谨慎操作！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "删除",
                        closeOnConfirm: false
                    }, function () {
                        deleteImage($(btnRemove).data('id'));
                        $(btnRemove).parents('div.col:first').remove();
                        //$('.upload-panel').fadeIn();
                        swal("删除成功！", "您已经永久删除了这条信息。", "success");
                    });
                });
                $('.mix-images').append(el);
            }

            Kmer.Uploader({
                el: 'input[type=file]',
                Path: 'USER',
                OnProgress: function (f, pc) {
                    $('.progress').show();
                    $('.progress-bar').css('width', pc.toString() + '%').text(pc.toString() + '%');
                },
                OnAllComplete: function () {
                    $('.progress').hide();
                },
                OnComplete: function (f, data) {
                    if (data.Success === true) {
                        var file = data.Data;
                        addImage(file);
                        $('.upload-panel').fadeOut();
                    } else {
                        bootbox.alert("上传错误，请重新选择图片（JPG、小于5Mbs）\n" + data.Message);
                    }
                }
            });
            $('#div-addImage,button.fa-upload').click(function () {
                $('input[type=file]').click();
            });

            //初始化日期控件
            var start = {
                elem: "#ContractBeginDate",
                format: "YYYY-MM-DD",
                min: "2015-12-01",
                max: "2099-12-01",
                istime: true,
                istoday: false,
                choose: function (datas) {
                    end.min = datas;
                    end.start = datas
                }
            };
            var end = {
                elem: "#ContractEndDate",
                format: "YYYY-MM-DD",
                min: laydate.now(),
                max: "2099-12-01",
                istime: true,
                istoday: false,
                choose: function (datas) {
                    start.max = datas
                }
            };
            var searchstart = {
                elem: "#search-start",
                format: "YYYY-MM-DD",
                min: "2015-12-01",
                max: "2099-12-01",
                istime: true,
                istoday: false,
                choose: function (datas) {
                    searchend.min = datas;
                    searchend.start = datas
                }
            };
            var searchend = {
                elem: "#search-end",
                format: "YYYY-MM-DD",
                min: "2015-12-01",
                max: "2099-12-01",
                istime: true,
                istoday: false,
                choose: function (datas) {
                    searchstart.max = datas
                }
            };
            laydate(searchstart);
            laydate(searchend);
            laydate(start);
            laydate(end);

            //初始化图片展示
            $(".fancybox").fancybox({
                openEffect: "none",
                closeEffect: "none"
            });
            //用于记录页数
            var page = 1;
            //用于记录每页多少条记录
            var size = 500;

            var ShopID = 0;
            var isCreate = true;
            //加载信息列表
            var loadList = function (page) {
                if ($('.footable thead').children().size() == 0)
                    tableControl.initThead2('.footable', ['序号', '客户代码', '店铺编码', '店铺名称', '注册名称', '营业执照号', '图片', '店铺注册地址', '开户行', '账号', '店铺店长', '店铺电话', '合同开始日期', '合同结束日期', '合同扣点']);
                pageControl.init('CsrdClient', 'GetCsrdClientList', {
                    CodeOrName: $('#search-CodeOrName').val(),
                    BeginDate: $('#search-start').val(),
                    EndDate: $('#search-end').val(),
                    Page: page,
                    alwaysCallBack: function () {
                        ShopID = 0;
                        $('#editBtn').attr('disabled', 'disabled');
                        $('#deleteBtn').attr('disabled', 'disabled');
                    }
                }, function (result) {
                    page = result.page;
                    var tBody = [];
                    if (!Y.checkNull(result.data)) {
                        if (result.data.Items.length > 0) {
                            result.data.Items.map(function (item, i) {
                                var tempTr = {
                                    trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd'),
                                    children: [
                                        { tdText: item.ClientID, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ClientID' },
                                        { tdText: (item.ClientCode || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ClientCode' },
                                        { tdText: item.ShopID, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide ShopID' },
                                        { tdText: (item.ShopCode || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ShopCode' },
                                        { tdText: (item.ShopName || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ShopName' },
                                        { tdText: (item.RegistName || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'RegistName' },
                                        { tdText: (item.RegistCode || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'RegistCode' },
                                        { tdText: item.RigistImgID, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide RigistImgID' },
                                        { tdText: '', c: 0, r: 0, tdHtml: item.ImgUrl == "" ? '<img alt="image" src="../assets/img/s.gif" class="itemPic" />' : '<img alt="image" src="' + item.ImgUrl + '" class="itemPic" />', tdId: '', tdClass: 'ImgUrl' },
                                        { tdText: (item.RedistAddress || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'RedistAddress' },
                                        { tdText: (item.BankName || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'BankName' },
                                        { tdText: (item.AccountCode || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'AccountCode' },
                                        { tdText: (item.ShopLinkMan || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ShopLinkMan' },
                                        { tdText: (item.ShopTelePhone || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ShopTelePhone' },
                                        { tdText: item.ContractBeginDate.substring(0, 10), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ContractBeginDate' },
                                        { tdText: item.ContractEndDate.substring(0, 10), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ContractEndDate' },
                                        { tdText: (item.Discount || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'Discount' },
                                    ]
                                };
                                tBody.push(tempTr);
                            })
                        }
                        rScroll();
                    }
                    tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 7, null);
                    _ClientID = "";
                    _ClientCode = "";
                    _ShopCode = "";
                    _ShopID = "";
                    _ShopName = "";
                    _RegistName = "";
                    _RegistCode = "";
                    _RedistAddress = "";
                    _BankName = "";
                    _AccountCode = "";
                    _ShopLinkMan = "";
                    _ShopTelePhone = "";
                    _ContractBeginDate = "";
                    _ContractEndDate = "";
                    _Discount = "";
                });
            }

            //新增按钮
            $('.btns-container').on('click', '#addBtn', function () {
                isCreate = true;
                $('.editTitle').text('新增-客户信息');
                $('.ShowClientCode').text('客户代码');
                $('#RegistName').val(""),
                $('#ShopName').val(""),
                $('#ShopCode').val(""),
                $('#ShopLinkMan').val(""),
                $('#ShopTelePhone').val(""),
                $('#RegistCode').val(""),
                $('#RedistAddress').val(""),
                $('#BankName').val(""),
                $('#AccountCode').val(""),
                $('#Discount').val(""),
                $('#ContractBeginDate').val(""),
                $('#ContractEndDate').val(""),
                $('#ContractCode').val("")
                $('#ContractState').val("")
                $(".mix-images").children().remove();
                $('.upload-panel').fadeIn();
            });
            //编辑按钮
            $('.btns-container').on('click', '#editBtn', function () {
                Y.API2('CsrdClient', 'GetID', {
                    ShopID: _ShopID
                }, function (data) {
                    if (data.Success === false) {
                    } else {
                        // $(".mix-images").children().remove();
                        isCreate = false;
                        // $('.upload-panel').hide();
                        $('.editTitle').text('编辑-客户信息');
                        $('.ShowClientCode').text('客户代码--' + data.ClientCode);
                        $('#RegistName').val(data.RegistName),
                        $('#ShopName').val(data.ShopName),
                        $('#ShopId').val(data.ShopID),
                        $('#ShopCode').val(data.ShopCode),
                        $('#ShopLinkMan').val(data.ShopLinkMan),
                        $('#ShopTelePhone').val(data.ShopTelePhone),
                        $('#RegistCode').val(data.RegistCode),
                        $('#RedistAddress').val(data.RedistAddress),
                        $('#BankName').val(data.BankName),
                        $('#AccountCode').val(data.AccountCode),
                        $('#Discount').val(data.Discount),
                        $('#ContractBeginDate').val(data.ContractBeginDate.substring(0, 10)),
                        $('#ContractEndDate').val(data.ContractEndDate.substring(0, 10)),
                        $('#ContractCode').val(data.ContractCode),
                        $('#ContractState').val(data.ContractState),
                        $('.mix-images').empty();
                        if (data.RigistImgID != undefined) {
                            addOldImage({
                                Title: '',
                                ID: data.RigistImgID,
                                Url: data.ImgUrl
                            });
                            $('.upload-panel').fadeOut();
                        }
                        else {
                            $('.upload-panel').fadeIn();
                        }
                    }
                });
            });
            commonUtil.initDeleteBtnEvent({
                callBack: function () {
                    Y.API2('CsrdClient', 'Remove', { ID: ClientID }, function (data) {
                        layer.closeAll('dialog');
                        if (data.Success == false) {
                            swal('删除失败', data.Message, 'error');
                        } else {
                            swal('删除成功', '该信息已被你永久删除', 'success');
                            loadList(1);
                        }
                    });
                }
            });
            //批量添加任务
            $(".btns-container").on("click", '#importBtn', function () {
                $.ImportExcelTemplate({
                    filetype: 'Baseshelf', filename: '客户信息', action: 'ImportTemplate', after: function () {
                        //回调方法
                        loadList(1);
                    }
                });
            });

            $('.btns-container').on('click', '#btn-search', function () {
                loadList(1);
            });

            //选中记录
            $('#pageList').on('click', 'tr', function () {
                //_ClientID = $(this).find('.ClientID').text();
                //_ClientCode = $(this).find('.ClientCode').text();
                //_ShopCode = $(this).find('.ShopCode').text();
                _ShopID = $(this).find('.ShopID').text();
                //_ShopName = $(this).find('.ShopName').text();
                //_RegistName = $(this).find('.RegistName').text();
                //_RegistCode = $(this).find('.RegistCode').text();
                //_RedistAddress = $(this).find('.RedistAddress').text();
                //_BankName = $(this).find('.BankName').text();
                //_AccountCode = $(this).find('.AccountCode').text();
                //_ShopLinkMan = $(this).find('.ShopLinkMan').text();
                //_ShopTelePhone = $(this).find('.ShopTelePhone').text();
                //_ContractBeginDate = $(this).find('.ContractBeginDate').text();
                //_ContractEndDate = $(this).find('.ContractEndDate').text();
                //_Discount = $(this).find('.Discount').text();
                //_ImageID = $(this).find('.RigistImgID').text();
                //_ImageURL = $(this).find('.ImgUrl .itemPic').attr("src");
                if (!Y.checkNull(_ShopID)) {
                    $('#editBtn').removeAttr('disabled');
                    $('#deleteBtn').removeAttr('disabled');
                }
                $('.footable tr').removeClass('check');
                $(this).addClass('check');
            });

            //店铺自动补全
            $('#ShopName').typeahead({
                source: function (query, process) {
                    var parameter = { query: query };
                    $('#ShopName').val();
                    $('#ShopCode').val();
                    $('#ShopId').val();
                    $('#ShopLinkMan').val();
                    $('#ShopTelePhone').val();
                    Y.API2('CsrdClient', 'GetShopBaseInfo', {
                        Keys: $('#ShopName').val()
                    }, function (data) {
                        if (data.Success == false) {
                            swal(data.Message, '', 'error');
                        } else {
                            var results = data.map(function (item) {
                                return JSON.stringify(item);
                            })
                            process(results);
                        }
                    });
                },
                highlighter: function (item) {
                    var item = JSON.parse(item);
                    return '名称：' + item.shopname + '　编号：' + item.shopcode;
                },
                updater: function (item) {
                    var item = JSON.parse(item);
                    $('#ShopName').val(item.shopname);
                    $('#ShopId').val(item.shopid);
                    $('#ShopCode').val(item.shopcode);
                    $('#BigAreaName').val(item.BigAreaName);;
                    $('#ShopLinkMan').val(item.Manage);
                    $('#ShopTelePhone').val(item.telphone);
                    return item.shopname;
                }
            });

            //删除
            commonUtil.initDeleteBtnEvent({
                callBack: function () {
                    Y.API2('CsrdClient', 'Remove', { ShopID: _ShopID }, function (data) {
                        layer.closeAll('dialog');
                        if (data.Success == false) {
                            swal('删除失败', data.Message, 'error');
                        } else {
                            swal('删除成功', '该信息已被你永久删除', 'success');
                            //刷新列表
                            loadList();
                        }
                    });
                }
            });

            loadList(1);
            //保存基本信息(新增或编辑)
            $('#addModuleBtn').click(function () {
                if (!CheckDataValid('#checkModuleForm')) {
                    return false;
                }
                //检验通过后执行新增或者编辑
                var action = '';
                var successText = '';
                if (isCreate) {
                    action = 'Create';
                    successText = '新增成功';
                } else {
                    action = 'Modify';
                    successText = '编辑成功';
                }
                var imgs = [];
                $('div.mix-images button[data-id]').each(function (index, el) {
                    imgs.push($(el).data('id'));
                });
                var img = imgs[0];
                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('CsrdClient', action, {
                    RegistName: $('#RegistName').val(),
                    ShopName: $('#ShopName').val(),
                    ShopID: $('#ShopId').val(),
                    ShopCode: $('#ShopCode').val(),
                    ShopLinkMan: $('#ShopLinkMan').val(),
                    ShopTelePhone: $('#ShopTelePhone').val(),
                    RegistCode: $('#RegistCode').val(),
                    RedistAddress: $('#RedistAddress').val(),
                    BankName: $('#BankName').val(),
                    AccountCode: $('#AccountCode').val(),
                    Discount: $('#Discount').val(),
                    RigistImgID: img,
                    ContractBeginDate: $('#ContractBeginDate').val(),
                    ContractEndDate: $('#ContractEndDate').val(),
                    BigAreaName: $('#BigAreaName').val(),
                    ContractCode: $('#ContractCode').val(),
                    ContractState: $('#ContractState').val()
                }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal(successText, '', 'success');
                        //关闭新建  or 编辑框
                        $('#closeAddBox').click

                        //刷新列表
                        loadList(1);
                    }
                })
            })
        })
    </script>
</asp:Content>

